package cn.wolfcode.behavior.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class CSVReader {
    public static void main(String[] args) {
        String csvFile = null;
        String csvDelimiter = null;
        try {
            csvFile = "test.csv";
            csvDelimiter = ",";
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        ClassLoader classLoader = CSVReader.class.getClassLoader();
        try (InputStream inputStream = classLoader.getResourceAsStream(csvFile);
             BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
            String line;

            List<String> urlColumn = new ArrayList<>();
            while ((line = br.readLine()) != null) {
                // Skip empty lines
                if (line.trim().isEmpty()) {
                    continue;
                }

                String[] data = line.split(csvDelimiter);

                if (data[2].equals("地址") || data[2].equals("URL not found")) {
                    continue;
                }

                urlColumn.add(data[2]);

            }

            for (String url : urlColumn) {
                System.out.println(url);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}